<?php

/**
 * Error controller
 *
 * @uses       Zend_Controller_Action
 * @package    base
 * @subpackage Controller
 */
class ErrorController extends Zend_Controller_Action
{
    /**
     * errorAction() is the action that will be called by the "ErrorHandler" 
     * plugin.  When an error/exception has been encountered
     * in a ZF MVC application (assuming the ErrorHandler has not been disabled
     * in your bootstrap) - the Errorhandler will set the next dispatchable 
     * action to come here.  This is the "default" module, "error" controller, 
     * specifically, the "error" action.  These options are configurable, see 
     * {@link http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standar
     *
     * @return void
     */
	public function preDispatch(){
	    $this->getFrontController()->unregisterPlugin('Zen_Controller_Plugin_Block');
	}
	
    public function errorAction()
    {
    	$errors = $this->_getParam('error_handler');
        if($this->_request->isXmlHttpRequest()){
        	$this->_helper->layout()->disableLayout();
        	 echo $errors->exception;
        } 
		$response_code = null;
		$message = null;
        switch ($errors->type) { 
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                $response_code = 404;
                $message = '<b>404</b>:Такой страницы не существует<br/>К сожалению, такой страницы не существует.<br/> Вероятно, она была удалена, либо её здесь никогда не было.';
                break;
            case Zen_Controller_Plugin_ErrorHandler::EXCEPTION_TEMPORARY_UNAVAILABLE :
                // 503 error -- controller or action not found
                $response_code = 503;
                $message = '<b>503</b>Сайт временно недоступен';
                break;
            default:
                // application error 
                $response_code = 500;
                $message = '<b>500</b>:Ошибка сервера<br/> возможно вы набрали неверный адрес.';
                break;
        }
		
		$model = new Zen_List('pages_item');
		$one = $model->select()->getOne("`mode`=$response_code");
		$this->view->body = ($one) ? $one['text'] : false;
		
		$this->getResponse()->setHttpResponseCode($response_code);
		$this->view->message = $message;
		
        $this->view->exception = $errors->exception;
        $this->view->request   = $errors->request;

    }
}
